package today;

import javax.swing.plaf.synth.SynthOptionPaneUI;
import java.io.*;

public class TrancientTest {
    public static void main(String[] args) {
        test();
    }
    public static void test(){
        Teacher teacher=new Teacher("zhangsan","nan");
        System.out.println(teacher);
        try {
            ObjectOutputStream o=new ObjectOutputStream(
                    new FileOutputStream("D:\\temp/Trancient.txt")
            );
            o.writeObject(teacher);
            if (o!=null){
                o.flush();
                o.close();
            }
            System.out.println("对象保存成功");
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            ObjectInputStream oi=new ObjectInputStream(
                    new FileInputStream(new File("D:\\temp/Trancient.txt"))
            );
            Object object=oi.readObject();
            System.out.println(object);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
class Teacher implements Serializable {

    private String name;
    private transient String sex;

    public Teacher(String name, String sex ) {
        this.name = name;
        this.sex = sex;
    }

    public String toString() {
        return "name=" + name + ", sex=" + sex;
    }
}